import numpy as np
from sklearn.linear_model import LinearRegression


def cal_slope(y):
    x = np.arange(len(y)).reshape((-1, 1))
    # 建立模型
    model = LinearRegression().fit(x, y)

    # 查看结果
    r_sq = model.score(x, y)
    # print('coefficient of determination:', r_sq)  # 拟合程度
    # print('intercept:', model.intercept_)
    # print('slope:', model.coef_)
    return model.coef_


